<template>
  <div id="bing" class="bing-container" />
</template>

<script>
import * as echarts from 'echarts'
import { bingData } from '@/api/tao'
export default {
  name: 'BingPage',
  data() {
    return {
      option: {
        tooltip: {
          trigger: 'item'
        },
        legend: {
          top: '5%',
          left: 'center'
        },
        series: [
          {
            name: 'Access From',
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 2
            },
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 40,
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: [
              { value: 1048, name: 'Search Engine' },
              { value: 735, name: 'Direct' },
              { value: 580, name: 'Email' },
              { value: 484, name: 'Union Ads' },
              { value: 300, name: 'Video Ads' }
            ]
          }
        ]
      }
    }
  },
  watch: {
    option: {
      handler(newVal, oldVal) {
        var myChart = echarts.init(document.getElementById('bing'))
        if (newVal) {
          myChart.setOption(newVal)
        } else {
          myChart.setOption(oldVal)
        }
      },
      deep: true
    }
  },
  mounted() {
    var myChart = echarts.init(document.getElementById('bing'))
    myChart.setOption(this.option)
  },
  created() {
    this.getData()
  },
  methods: {
    async getData() {
      console.log(111);
      const {data} = await bingData()
      // console.log(res)
      this.option.series[0].data = data.data[0].num
      this.option.series[0].name = data.data[0].title
    }
  }
}
</script>

<style lang="scss">
#bing{
    height: 400px;
}
</style>
